<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script type="text/javascript" src="js/jquery-3.5.1.js"></script>
    <title>Document</title>
    <style>
        table,
        td,
        th {
            border: 1px solid black;
            border-collapse: collapse;
        }

        table {
            width: 500px;
            text-align: center;
        }

        tr {
            height: 35px;
        }
    </style>
</head>

<body>
    <button id="getBtn">获取所有水果信息</button>
    <div id="showData"></div>
    <script type="text/javascript">
        $("#getBtn").click(function () {
            $.ajax({
                type: 'get',
                url: 'http://localhost:3000/fruits',
                success: function (data) {
                    var h = ""
                    h += "<table border='1'>"
                    h += "<thead><th>ID</th><th>name</th><th>price</th></thead>"
                    h += "<tbody>"
                    for (var i = 0; i < data.length; i++) {
                        var o = data[i]
                        h += "<tr>"
                        h += "<td>" + o.id + "</td><td>" + o.name + "</td><td>" + o.price + "</td>"
                        h += "</tr>"
                    }
                    h += "</tbody>"
                    h += "</table>"
                    $("#showData").empty().append(h)
                },
                error: (function () {
                    alert("get error")
                })
            })
        })
    </script>
</body >
</html >